<?php
include 'dbconfig.php';
include 'opendb.php';

$ID= $_GET['userID'];
$and   = $ID?   "AND wp_users.ID=$ID" : "";

$doc = new DomDocument ('1.0', 'utf-8');
$root = $doc->appendChild ($doc->createElement ('projects'));

function insertEntry ($node, $entry) {
	$node->appendChild ($entry);
}

$rows = mysql_query ("SELECT wp_users.user_login as user_id,
wp_projects.PROJ_ID as proj_id, 
wp_projects.PROJ_NAME as proj_name
FROM wp_users, wp_projects, wp_projectcontributors
WHERE wp_users.ID = wp_projectcontributors.CONTRIBUTOR_ID
AND wp_projects.PROJ_ID = wp_projectcontributors.PROJ_ID
AND wp_projects.IS_DELETED='0' $and");

/*$rows = mysql_query ("SELECT $fields FROM $table $where $orderBy");*/
if ($rows) {
	while ($row = mysql_fetch_assoc ($rows)) {
		$entry = $doc->createElement ('project');
		foreach ($row as $fieldName => $fieldValue) {
			$field = $entry->appendChild ($doc->createElement ($fieldName));
			$field->appendChild ($doc->createTextNode ($fieldValue));
		}
		insertEntry ($root, $entry);
	}
}


header ('Content-Type: text/xml');
echo $doc->saveXML ();
?>